package oj;

public class Day23F {
    public int getValue(int[] gifts, int n) {
        if(gifts==null || gifts.length==0){
            return 0;
        }
        int result=gifts[0];
        int times=1;
        for (int i = 1; i < gifts.length; i++) {
            if(times!=0){
                if(gifts[i]==result){
                    ++times;
                }else {
                    --times;
                }
            }else {
                result=gifts[i];
                times=1;
            }
        }
        times=0;
        for (int i = 0; i < gifts.length; i++) {
            if(gifts[i]==result){
                times++;
            }
        }
        return (times>gifts.length/2)?result:0;
    }
}
